package com.zhuoyue.biz.core.command.impl.alarm;

import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zhuoyue.biz.core.command.model.RadarConfigurationCmd;
import com.zhuoyue.common.utils.CmdUtils;

/**
 * 86型人体感应面板控制类
 *
 * @author Administrator
 */
public class HumanBodySensorPanelControl0Faa8105 {
    private static final String CMD_MODEL = "0201${gatewayMac}${deviceMac}0FAA1302${nightLightTime}";
    /**
     * 小夜灯数据帧设置模型设置
     */
    private static final String TIME_00 = "00";
    private static final String TIME_FF = "FF";
    private static final Integer TIME_10 = 10;
    private static final Integer TIME_60 = 60;

    public static String getCommand(String controlParam) {
        Map<String, String> map = (Map) JSONObject.parse(controlParam);

        Map<String, String> actionsMap = (Map) JSONObject.parse(JSON.toJSONString(map.get("actions")));

        String nightLightTime = actionsMap.get("nightLightTime");
        if (TIME_00.equals(nightLightTime)) {
            nightLightTime = "0000";
        } else if (TIME_FF.equals(nightLightTime)) {
            nightLightTime = "FF00";
        } else if (Integer.parseInt(nightLightTime) >= TIME_10 && Integer.parseInt(nightLightTime) <= TIME_60) {
            nightLightTime = CmdUtils.intToHexTwo(Integer.parseInt(nightLightTime)) + "00";
        } else {
            return null;
        }
        String cmd = new RadarConfigurationCmd(map.get("gatewayMac"), map.get("deviceMac"), nightLightTime).getCmd(CMD_MODEL);
        return cmd;
    }

}

